package com.theaf.basemodule.web.controller;

import com.theaf.basemodule.common.api.MesTemplateService;
import com.theaf.basemodule.common.condition.MesTemplateCondition;
import com.theaf.basemodule.common.dto.mesTemplate.MesTemplateDTO;
import com.theaf.basemodule.common.vo.mesTemplate.MesTemplateVo;
import com.theaf.core.web.ResultHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/mesTemplate")
@Api(description = "消息模版管理")
public class MesTemplateController {

    @Resource
    private MesTemplateService templateService;

    @RequestMapping(value = "/template", method = RequestMethod.POST)
    @ApiOperation(value = "新增/修改模版", httpMethod = "POST", response = Object.class, position = 1)
    public Object addTemplate(@RequestBody MesTemplateVo vo) {
        templateService.save(vo);
        return  ResultHandler.success(vo.getId());
    }

    @RequestMapping(value = "/template/{id:\\d+}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除模版", httpMethod = "DELETE", response = Boolean.class, position = 3)
    @ApiImplicitParam(value = "模版id", name = "id", dataType = "long", paramType = "path")
    public Object deleteTemplate(@PathVariable("id") Long id) {
        templateService.delete(id);
        return ResultHandler.success(true);
    }



    @RequestMapping(value = "/templateList", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取消息模版", httpMethod = "POST", response = MesTemplateDTO.class, position = 4)
    public Object querytemplate(@RequestBody MesTemplateCondition condition) {
        return ResultHandler.success(templateService.query(condition));
    }

    @RequestMapping(value = "/template/{id:\\d+}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取模版信息", httpMethod = "GET", response = MesTemplateDTO.class, position = 5)
    @ApiImplicitParam(value = "模版id", name = "id", dataType = "long", paramType = "path")
    public Object findtemplate(@PathVariable Long id) {
        return ResultHandler.success(templateService.find(id));
    }
}
